//
//  MTTableViewController.h
//  iMeituanHD
//
//  Created by psy on 12-2-29.
//  Copyright (c) 2012年 meituan. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "CMBaseViewController.h"


@protocol MTTableViewControllerDelegate <NSObject>

- (void)tableController:(UIViewController *)controller didSelectRowAtIndexPath:(NSIndexPath *)indexPath selectedItem:(id)item forCell:(UITableViewCell *)cell;

@end

@interface MTTableViewController : CMBaseViewController <UITableViewDataSource,UITableViewDelegate> {
    UITableView *_tableView;
    NSMutableArray *_items;
}
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,assign)UITableViewStyle tableStyle;
@property (nonatomic,strong)NSMutableArray *items;//不含section信息
@property (nonatomic,strong)NSMutableArray *sections;//section的title数组，数量可以小于items的组数
@property (nonatomic,unsafe_unretained)id/*<MTTableViewControllerDelegate>*/ delegate;

- (id)initWithStyle:(UITableViewStyle)tableStyle;
@end




////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
@interface MTTableItem : NSObject {
    NSString *_cellClassName;
    int _cellHeight;
    SEL _selectAction;
}
@property (nonatomic,copy)NSString *cellClassName;
@property (nonatomic,unsafe_unretained)id target;
@property (nonatomic,unsafe_unretained)SEL selectAction;
@property (nonatomic,assign)int cellHeight;

+ (id)item;
- (void)setSelectAction:(SEL)selectAction target:(id)target;
- (int)cellHeightWithWidth:(int)width;
@end

@interface MTTableCell : UITableViewCell {
    MTTableItem *_item;
}
@property (nonatomic,strong)MTTableItem *item;
- (id)initWithStyle:(UITableViewCellStyle)style;
@end

////////////////////////////////////////////////////////////////////////////////////////////////////
@interface MTTableMenuItem : MTTableItem 
@end

@interface MTTableMenuCell : MTTableCell {
    NSMutableArray *_menuActionNames;
    NSMutableArray *_menuItems;
    BOOL _canBecomeFirstResponder;
}
- (void)beginLongPressMenuConfig;
- (void)addLongPressMenuWithName:(NSString*)menuName actionName:(NSString*)actionName;
- (void)finishLongPressMenuConfig;
- (void)registLongPressGestureRecongnizer;
@end
////////////////////////////////////////////////////////////////////////////////////////////////////
@interface MTTableSingleTitleItem : MTTableItem
@property (nonatomic,copy)NSString *title;
@property (nonatomic,strong)UIFont *font;
@property (nonatomic,strong)UIColor *textColor;
@property (nonatomic,assign)UITextAlignment textAlignment;
- (id)initWithTitle:(NSString *)title;
+ (id)itemWithTitle:(NSString *)title;
+ (id)itemWithTitle:(NSString *)title font:(UIFont *)font;
+ (id)itemWithTitle:(NSString *)title font:(UIFont *)font textColor:(UIColor *)textColor;
@end

@interface MTTableSingleTitleCell : MTTableCell 
@end

////////////////////////////////////////////////////////////////////////////////////////////////////
@interface MTTableControlItem : MTTableItem {
    NSString *_title;
    UIControl *_control;
}
@property (nonatomic,copy)NSString *title;
@property (nonatomic,strong)UIControl *control;
- (id)initWithTitle:(NSString *)title control:(UIControl *)control;
@end

@interface MTTableControlCell : MTTableCell {
    
}
@end

////////////////////////////////////////////////////////////////////////////////////////////////////
@interface MTTableDetailItem : MTTableMenuItem
@property (nonatomic,strong)UIImage *icon;
@property (nonatomic,copy)NSString *title;
@property (nonatomic,copy)NSString *detail;
@property (nonatomic,strong)UIImage *accessIcon;
- (id)initWithTitle:(NSString *)title detail:(NSString *)detail;
- (id)initWithIcon:(UIImage *)icon title:(NSString *)title detail:(NSString *)detail accessIcon:(UIImage *)accessIcon;
@end

@interface MTTableDetailCell : MTTableMenuCell
@property (nonatomic,strong)UIImageView *accessView;
@end

////////////////////////////////////////////////////////////////////////////////////////////////////
//加载更多的cell
@interface MTTableMoreItem : MTTableItem
@property (nonatomic,copy)NSString *moreText;
- (id)initWithText:(NSString *)moreText;
@end

@interface MTTableMoreCell : MTTableCell
@property (nonatomic,strong)UILabel *moreTextLabel;
@property (nonatomic,assign)BOOL loading;
@property (nonatomic,strong)UIActivityIndicatorView *activeView;

@end

////////////////////////////////////////////////////////////////////////////////////////////////////
//用于单选的cell group
@interface MTTableRadioItem : MTTableItem
@property (nonatomic,assign)BOOL isSelected;
@property (nonatomic,copy)NSString *groupName;//default is subClass's className; groupName decides which cells are in a group.
@end

@interface MTTableRadioCell : MTTableCell
- (void)setRadioSelected:(BOOL)isSelected;
@end